with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
With Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with IO; use IO;
with Logging;
with Smart_Arguments;
with Parser;
with Parser_Filter;

procedure Mkv4ada is

   MKV_File : Smart_Arguments.Argument_Type;
   Help : Smart_Arguments.Argument_Type;
   InFile_Ptr : IO.File_Type_Access;
   P : Parser.Parser;
   Print_Filter : Parser_Filter.Print_Filter_Type;
   Filter : Parser_Filter.ID_Filter_Type(16#a1#);

begin

   -- parse args
--     Smart_Arguments.Create_Positional_Argument
--       (Argument    => MKV_File,
--        Position  => 1,
--        Required    => true,
--        Short_Description => "mkv_file",
--        Description => "Input mkv file to analyze");
--

   Smart_Arguments.Create_Argument
     (Argument    => MKV_File,
      Short_Form  => "-mkv",
      Required    => true,
      Description => "Input mkv file to analyze",
      Number_Required_Subargs => 1,
      Subarg_Description => "mkv_file");

   Smart_Arguments.Create_Argument
     (Argument    => Help,
      Short_Form  => "-h",
      Description => "Display this help information");

   -- validate
   if Smart_Arguments.Argument_Present(Argument => Help) then
      Smart_Arguments.Display_Help(Short_Form_Only => false);
      return;
   end if;

   if not Smart_Arguments.Arguments_Valid then
      Set_Exit_Status(2);
      Put_Line(Standard_Error, Smart_Arguments.Get_Command_Line_Error_Description);
      New_Line;
      Smart_Arguments.Display_Help(Short_Form_Only => false);
      return;
   end if;

   InFile_Ptr := new IO.File_Type;

   -- read args
   InFile_Ptr.Name := To_Unbounded_String(Smart_Arguments.Get_Subargument(MKV_File,1));

   -- open files
   Logging.Info("Opening : " & To_String(InFile_Ptr.Name));
   Stream_IO.Open(InFile_Ptr.File, Stream_IO.In_File, To_String(InFile_Ptr.Name));
   InFile_Ptr.File_Access := Stream_IO.Stream(InFile_Ptr.File);

  -- InFile_Ptr := InFile'Access;
   P := Parser.New_Parser(InFile_Ptr);
   P.Parse(Print_Filter);
   --P.Parse(Filter);

   Logging.Info("Result size : " & Integer'Image(Integer(Filter.Result.Length)));


   Stream_IO.Close(InFile_Ptr.File);


end Mkv4ada;



